package gold.contest;

import gold.utils.InputUtil;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC5714 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String evaluate(String s, List<List<String>> knowledge) {
            Map<String, String> knowledgeMap = new HashMap<>();
            for (List<String> kn : knowledge) {
                knowledgeMap.put(kn.get(0), kn.get(1));
            }

            StringBuilder sb = new StringBuilder();
            int i = 0;
            while (i < s.length()) {
                char cur = s.charAt(i);
                if (cur == '(') {
                    int start = i + 1, end = i + 1;
                    while (s.charAt(end) != ')') ++end;
                    String curKey = s.substring(start, end);
                    sb.append(knowledgeMap.getOrDefault(curKey, "?"));
                    i = end + 1;
                } else {
                    sb.append(cur);
                    ++i;
                }
            }

            return sb.toString();
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<List<String>> arr = InputUtil.toDoubleStringList("[[\"a\",\"b\"],[\"b\",\"a\"]]");
        System.out.println(solution.evaluate("(a)(b)", arr));
    }

    public static void main(String[] args) throws Exception {
        LC5714 an = new LC5714();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
